package com.hui.util;

import com.hui.entity.Menu;


import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @date 2023/2/4 10:58
 */
public class MenuUtil {

    public static List<Menu> conversionList(List<Menu> list) {


        List<Menu> newList = new ArrayList<>();

        for (int i = 0; i < list.size(); i++) {
            Menu menu = list.get(i);
            //筛选一级菜单
            if (menu.getMenuLevel() == 1) {

                List<Menu> childList = new ArrayList<>();

                for (int j = 0; j < list.size(); j++) {
                    //判断是否为二级菜单
                    if (list.get(j).getMenuLevel() == 2 && list.get(j).getParentMenuCode().equals(menu.getMenuCode())) {
                        childList.add(list.get(j));
                    }
                }
                menu.setChildList(childList);//将二级菜单放入Menu实体的ChildList集合属性中保存，从而实现不同等级菜单分离
                newList.add(menu);
            }
        }

        return newList;
    }


}
